import { createBrowserRouter, RouteObject } from "react-router-dom";

import { lazy } from "react";
import { Navigate } from "react-router-dom";

// 懒加载
import lazyload from "./lazyload";

const Layout = lazy(() => import("../layout"));
const Store = lazy(() => import("../pages/store"));
const Product = lazy(() => import("../pages/product"));
const Order = lazy(() => import("../pages/order"));
const OrderXiangqing = lazy(() => import("../pages/order/OrderXiangqing"));
const ProductXiangqing = lazy(() => import("../pages/order/ProductXiangqing"));
const OrderCreate = lazy(() => import("../pages/order/components/create"));
const OrderTuihuo = lazy(() => import("../pages/order/components/Tuihuo"));
const Login = lazy(() => import("../pages/login"));
const ProductRiceText = lazy(
  () => import("../pages/product/components/productRiceText")
);
const Customers = lazy(() => import("../pages/customers"));
const CustomersXQ = lazy(
  () => import("../pages/customers/components/xiangqing")
);
const CustomersXQHP = lazy(
  () => import("../pages/customers/components/xiangqing/component/hepinkehu")
);
const CustomersNew = lazy(() => import("../pages/customers/components/create"));

// 集中式路由
const routes: RouteObject[] = [
  {
    path: "/login",
    element: lazyload(<Login />),
  },
  {
    path: "/",
    element: lazyload(<Layout />),
    children: [
      { index: true, element: lazyload(<Store />) },
      { path: "eriodesign", element: lazyload(<Store />) },
      { path: "product", element: lazyload(<Product />) },
      { path: "order", element: lazyload(<Order />) },
      { path: "order/:id", element: lazyload(<OrderXiangqing />) },
      { path: "order/:id/return", element: lazyload(<OrderTuihuo />) },
      { path: "order/product/:id", element: lazyload(<ProductXiangqing />) },
      {
        path: "order/product/ProductRiceText/:id",
        element: lazyload(<ProductRiceText />),
      },
      { path: "order/create", element: lazyload(<OrderCreate />) },
      { path: "customers", element: lazyload(<Customers />) },
      { path: "customers/:id", element: lazyload(<CustomersXQ />) },
      { path: "customers/:id/merge", element: lazyload(<CustomersXQHP />) },
      { path: "customers/new", element: lazyload(<CustomersNew />) },
    ],
  },
  // { path: "/404", element: lazyload(<Err404 />) },
  // { path: "/500", element: lazyload(<Err500 />) },
  // { path: "*", element: <Navigate to="/404" /> },
];

const router = createBrowserRouter(routes);

export default router;
